// packageInsurance/pages/insurance-report-online/insurance-report-online.js
import { getReportDetail, revokeReport, getInsureCompanyList } from '../../api/long-insure'
import {confirm,toast} from '../../../utils/util'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        arr:[{
            count:"保司审核金额",
            voucher:"5920.59+900提供凭证",
            time:"2023-03-10"
        },{
            count:"初审结束",
            voucher:"",
            time:""
        },{
            count:"质量中",
            voucher:"",
            time:""
        },
    ],
    detailInfo: {},
    pickUp:true
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
       console.log(options,'options')
       this.getInsuranceReportDetail(options.id)
    },
    getInsuranceReportDetail(id){
        getReportDetail({id:id}).then(async res=>{
            console.log(res,'res')
            // res.params.fileUrl.forEach((item,index)=>{
            //     res.params.fileUrl[index].fileUrl = JSON.parse(item.fileUrl)
            // })
            const insureCompanyList = await getInsureCompanyList() || []
            res.canShowAddMaterial = insureCompanyList.some(i => i === res.insurCompany)

            res.outDangerDate = res.outDangerDate.slice(0,10)
            res.reportCaseResultList.map((item,index) => {
                res.reportCaseResultList[index].createTime = item.createTime.slice(0,10)
            })
            this.setData({
                detailInfo:res,
            })
        })
    },
    
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },
    // 撤销报案
    async onRevokeReportCase(event){
        console.log(event,'event')
       confirm('确认撤销当前报案吗').then(() =>{
        revokeReport({id:this.data.detailInfo.id}).then(() => {
            this.getInsuranceReportDetail(this.data.detailInfo.id)
            toast('撤销成功')
        })
       })
        
    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },
    onRetract(event){
      console.log(event,'event')
      if(!this.data.pickUp){
        this.setData({
            pickUp:true
          },() =>{
              console.log(this.data.pickUp,'pickUp')
          })
      }else{
        this.setData({
            pickUp:false
          },() =>{
              console.log(this.data.pickUp,'pickUp')
          })
      }

    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    },

    toExtraMaterial(event) {
        const { type, id } = event.currentTarget.dataset
        wx.navigateTo({
            url: `/packageInsurance/pages/extra-material/extra-material?insureType=long&insureCompany=${type}&id=${id}`
        })
    }
})